package com.example.demo.Demo1;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@RequestMapping("/user")
@RestController
public class UserController {
    @RequestMapping("/login")
    public boolean login(String username, String password, HttpServletRequest request){
        System.out.println(username);
        System.out.println(password);
         if(username==null||username.length()==0||password==null||password.length()==0){
    return false;
    }
         if(username.equals("admin")&&password.equals("admin")){
             HttpSession session = request.getSession(true);
             session.setAttribute("username",username);
             return true;
         }
          return false;
         }

         @RequestMapping("userInfo")
    public String userInfo(HttpServletRequest request){
        HttpSession session = request.getSession(false);
        if(session == null){
            return "用户未登录";
        }
      String outcome = (String) session.getAttribute("username");
        return outcome;
         }
}
